﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./jquery-3.5.1.min.js"></script>
</head>
<body>
<input type="file" id="uploadFile" name="smfile" enctype="multipart/form-data"/>
<div id="res"></div>
<script>
    //上传图片  返回一个网络图片路径url
    $('#uploadFile').change(function(){
        var f=this.files[0];
        var formData=new FormData();
        formData.append('smfile',f);    //强调一下这个对象的name一定是smfile，不能变
        console.log(formData)
        $.ajax({
            url: 'https://sm.ms/api/v2/upload',
            type: 'POST',
            success: function(data){
                console.log(data);
                annotationsObject = JSON.parse(data);
                console.log(annotationsObject);
                console.log(typeof annotationsObject)
                $('#res').html(JSON.stringify(annotationsObject.data.url));//即图片的网络url//获取后可以使用
            },
            error: function(data){
                console.log(data);
            },
            data:formData,
            cache: false,
            contentType: false,
            processData: false

        });
    });

</script>
</body>
</html>